package com.ican.util;

import java.security.MessageDigest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MD5Util {
    private final static Logger logger = LoggerFactory.getLogger(MD5Util.class);
        
    public static String Md5(String resource){
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(resource.getBytes());
            byte b[] = md.digest();
            int i;
            StringBuffer buf = new StringBuffer("");
            for (int offset = 0; offset < b.length; offset++) {
                    i = b[offset];
                    if (i < 0)
                    i += 256;
                    if (i < 16)
                    buf.append("0");
                    buf.append(Integer.toHexString(i));
            }
            return buf.toString();
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            return resource;
        }
    }
    
    public static void main(String[] args){
        System.out.println(Md5("asdfas5486sd4f6as4d5a4d8586dfas"));
    }
    
}
